#ifndef SCNTYPES_H_
#define SCNTYPES_H_

#include "../scnedit.h"

struct point3f
{
	f32 x,y,z;
};
struct point2f
{
	f32 u,v;
};
struct point2i
{
    u32 a;
    u32 b;
};
struct tempLight_t
{
    point3f color;
    f32 radius;
    point3f origin;
};

struct scnHeader_t
{
/* address | type| meaning*/
/*--------------------*/
/* 0x00 */	char    magic[4];
/* 0x04 */	u32     version;
/* 0x08 */	u32     datalen;
/* 0x0c */	u32     n_ents;
/* 0x10 */	u32     n_solids;
/* 0x14 */	u32     solid0_offset;  //should always be 0x98
/* 0x18 */	u32     solid0_length;	//lengths of solid[0], ie, worldspawn
/* 0x1c */	u32     solids_offset;  //offset to solids[1]
/* 0x20 */	u32     solids_length;    //length of all other solids
/* 0x24 */	u32     unk2;
/* 0x28 */	u32     ents_offset;
/* 0x2c */	u32     unk3;
/* 0x30 */	u32     unk4;
/* 0x34 */	u32     ents_offset2;
/* 0x38 */	u32     ents_size;
/* 0x4c */	u32     unk5;
/* 0x40 */	u32     lmaps_offset;   //lightmaps start address
/* 0x44 */	u32     n_lights;   //number of light enteties
/*zeros follow...*/

};
struct scnSurf_t
{
    //IMPORTANT: keep order, we rely on it to read
    char texture[32];
	f32 unk[2];
	u16 flags,alpha;
	u16 lmsize_h, lmsize_v;
	u16 width, height; //width and height of tex, in pixels
	u32 vertidxstart;
	u16 planeidx;
	u16 vertidxlen;
	u16 more;
	char stuff2[10];
	u8 * shading;
//	char extra[?]	??
};

struct scnPlane_t
{
	f32 a,b,c,d;		//plane equation ax + by + cz + d = 0;
};
struct scnEntField_t
{
    char *key;
    char *value;
};

enum EScnMaterial
{
    ESM_DEFAULT     = 0x00,
    ESM_LIQUID      = 0x10,
    ESM_MUD         = 0x20,
    ESM_GRAVEL      = 0x30,
    ESM_PLASTER     = 0x40,
    ESM_CARPET      = 0x50,
    ESM_GLASS       = 0x60,
    ESM_WOOD        = 0x70,
    ESM_CREAKWOOD   = 0x80,
    ESM_BRICK       = 0x90,
    ESM_SHEETMETAL  = 0xA0,
    ESM_STEEL       = 0xB0
};

struct scnNode_t  //16 bytes
{
    s16 plane;  //splitting plane idx
    s8 area;   //?
    u8 material;

    s16 node1;  //node in front of plane
    s16 node2;  //node behind plane
    s16 nodep;  //parent node

    s16 cell;   //cell index
    s32 more;   //?
};

struct scnPortal_t
{
    char name[32];
    s32 nextcell; //cell idx this portal looks into
    scnPlane_t plane;
    f32 unk;        //float ?
    s32 n_verts;    //number of verts defining the portal
    point3f bb_verts[2]; //portal bounding box points
    point3f * verts;
};

struct scnRawCell_t //raw cell means it's the cell read not from the entity list
{
    char name[32];
    s32 n_nodesidxs;
    s32 n_portals;
    s32 n3; //?
    char skyname[32];
    u16 * nodesidxs; //index of nodes
    scnPortal_t * portals;
    //there is also more data here
};

#endif
